#pragma once
#include "cupid.h"

namespace cupid
{

class ThreadBase
{
public:		
	ThreadBase();

	virtual ~ThreadBase();

public:		
	bool	createThread(bool run = true);

	bool	resumeThread();	

	bool	closeThread(long msec = 0);

	/////////////////////////////////////////////////////////////////////
protected:	
	virtual	void	onInit() { }
	virtual bool	onProcess() = 0;		
	virtual void	onDestroy() { }

	/////////////////////////////////////////////////////////////////////
private:
	bool	isCloseEvent(long msec = 0);
	DWORD	threadProc();
	bool	isCreated() { return (m_thread != NULL); }

protected:
	HANDLE		m_thread;
	HANDLE		m_closeThreadEvent;

	/////////////////////////////////////////////////////////////////////
private:
	static DWORD WINAPI trueThreadProc(LPVOID param);
};
}